#include<iostream>
#include<vector>
#include<sstream>

using namespace std;

int main()
{
	int N;
	cin >> N;
	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	vector<int> data;
	for (int i = 0; i < N; i++)
	{
		string line;
		getline(cin, line);
		int num;
		stringstream ss(line);
		while (ss >> num)
		{
			data.push_back(num);
		}
	}
	int m = -1;
	int n = -1;
	int minid = 100000;
	int maxid = 0;
	for (auto id : data)
	{
		minid = min(minid, id);
		maxid = max(maxid, id);
	}
	vector<int> count(maxid + 1, 0);
	for (auto e : data)
	{
		count[e]++;
	}
	for (int i = minid; i <= maxid; i++)
	{
		if (count[i] == 0)
		{
			m = i;
		}
		if (count[i] > 1)
		{
			n = i;
		}
		/*if (m != -1 && n != -1)
			break;*/
	}

	cout << m << " " << n << endl;
	return 0;
}